%%%-------------------------------------------------------------------
%%% @author liuwentao
%%% @doc
%%%
%%% @end
%%% Created : 24. 5月 2021 15:56
%%%-------------------------------------------------------------------
-module(main).
-author("liuwentao").

%% API
-export([
    start/0
    , stop/0
    , stop_shell/0
]).

-include("common.hrl").

%% @doc 系统启动
start() ->
    start([crypto, emysql, main]).

start([]) -> ?INFO("应用启动完成");
start([App | T]) ->
    case application:start(App) of
        'ok' ->
            start(T);
        {'error', Msg} ->
            ?ERR("应用启动失败~w", [Msg]),
            ok
    end.

%% @doc 系统关闭
stop() ->
    ?INFO("系统关闭"),
    application:stop(main).

%% @doc 关闭游戏节点
stop_shell() ->
    [NodeNameStr] = init:get_plain_arguments(),
    NodeName = list_to_atom(NodeNameStr),
    ?INFO("关闭节点~w", [NodeName]),
    case net_adm:ping(NodeName) of
        pong ->
            rpc:cast(NodeName, main, stop, []);
        _ ->
            ok
    end,
    init:stop(),
    ok.


